<?php
	if ($_POST)
	{
		require('config.php');
		$origin = $_POST["origin"];
        $changeto = $_POST["changeto"];
		if (isset($_COOKIE['userid']) && $_COOKIE['userid'] != '')
		{
		    $stmt = $connection->prepare("select user_id from user_fav_lists where user_id=? and fav_type=?");
		    $stmt->bind_param("ss", $_COOKIE['userid'], $changeto);
		    $stmt->execute();
		    $stmt->store_result();
		    $row_cnt = $stmt->num_rows;
		    if ($row_cnt > 0)
            {
                echo "LISTEXIST"; 
            }
            else
            {
                $stmt = $connection->prepare('update user_fav_lists set fav_type=? where user_id=? and fav_type=?');
                $stmt->bind_param("sss",$changeto, $_COOKIE['userid'], $origin);
                $stmt->execute();
                $stmt = $connection->prepare('update user_fav set fav_type=? where user_id=? and fav_type=?');
                $stmt->bind_param("sss",$changeto, $_COOKIE['userid'], $origin);
                $stmt->execute();
                echo "true";
            }
		}
		else
		{
			echo "NOUSER";	
		}
        $connection->close();
	}
	else
	{
		echo "NOPOST";	
	}
?>
